<template>
	<view class="content">
		<view class="input-group">
			<view class="input-row border">
				<text class="title">手机号：</text>
				<m-input length=5 type="text" focus clearable v-model="user.phone" placeholder="请输入手机号"></m-input>
			</view>
			<view class="input-row border">
				<text class="title">密码：</text>
				<m-input type="password" displayable v-model="user.password" placeholder="请输入密码"></m-input>
			</view>
		</view>
		<view class="btn-row">
			<button type="primary" class="primary" @tap="register">注册</button>
		</view>
	</view>
</template>

<script>
	import mInput from '../../components/m-input.vue';
	import check from '../../common/graceChecker.js';
	export default {
		components: {
			mInput
		},
		data() {
			return {
				user: {
					phone: '',
					password: '',
					introducer_user_id:1
				}
			}
		},
		mounted() {
			console.log(process.env.NODE_ENV)
		},
		methods: {
			register() {
				let that = this
				var data = {
					'phone': that.user.phone,
					'password': that.user.password,
				}
				var rule = [{
						'name': 'phone',
						'checkType': 'phoneno',
						'errorMsg': that.message.phone,
					},
					{
						'name': 'password',
						'checkType': 'string',
						'checkRule': '1,12',
						'errorMsg': that.message.password,
					},
				]
				if (!check.check(data, rule)) {
					uni.showToast({
						icon: 'none',
						title: check.error
					});
					return;
				}
				that.apipost('/users/authorize/phone/pwd_register',that.user).then(res => {
					if(res.user_id){
						uni.showToast({
							icon: 'none',
							title: that.message.regok
						});
						return;
					}
				})
			}
		}
	}
</script>

<style>

</style>
